<?php
// include("conn.php");
// include("errorcode.php");
// include("checkAuth.php");

function viewMySchedule($userName, $userPassHash)
{
    $err=new ErrorCode();
	$us=$userName;
	//$us='Chen';
	if(checkAuthentication($userName,$userPassHash))
	{
		$conn=mysql_open();
		mysql_select_db("paradigmshift_dev", $conn);
		$iName=$userName;
		//$iName="dChen";
		$result=mysql_query("select roles.roleName,
paradigmshift_dev.roledate.dateID,
paradigmshift_dev.roledate.roleID,
paradigmshift_dev.roledate.startTime,
paradigmshift_dev.roledate.endTime,
paradigmshift_dev.roledate.shiftStatus,
paradigmshift_dev.dates.datestamp 
from  paradigmshift_dev.employees
left join (dates,roledate,account,roles) on paradigmshift_dev.roledate.empID=employees.empID and
paradigmshift_dev.dates.dateID=paradigmshift_dev.roledate.dateID
and paradigmshift_dev.roledate.empID=paradigmshift_dev.account.empID
and roles.roleID=roledate.roleID
where account.accName='".$iName."'",$conn);
		/*echo "<table id='users' class='ui-widget ui-widget-content'>
			<thead>
		<tr class='ui-widget-header '>
		<th>roleID</th>
		<th>empID</th>
		<th>dateID</th>
		<th>StartDate</th>
		<th>EndDate</th>
		<th>shiftStatus</th>
		<th>date</th>
		</tr>
		</thead>";*/
		$count=mysql_num_rows($result);
		if ($count<=0)
	    {
		     return null;
		     $error =$err->failRead;
		}
		while($row=mysql_fetch_array($result))
		{
			$array[] = array(
			'roleName'=>$row['roleName'],
			'roleID'=>$row['roleID'],
			'dateID'=>$row['dateID'],
			'startTime'=>$row['startTime'],
			'endTime'=>$row['endTime'],
			'shiftStatus'=>$row['shiftStatus'],
			'date'=>$row['datestamp']);
		}
		mysql_close($conn);
		return $array;
		$error=$err->successRead;
		//return $result;
	}
	else
	{
		//echo 'unknow user';
		$error =$err::failRead;
	}
}
?>